﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapWASTKE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWASTKE(DataRow dwData, DataRow dwDispo)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWASTKE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }

            MapWASTKE(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertWASTKE(dwLocal);
            }
            UpdateWASTKE(dwLocal);
        }
        public void InsertWASTKE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO WASTKE(WAKMANDANT, WAKKUNDNR, WAKWERK, WAKABT, WAKART, WAKVAR, WAKWCOL, WAKPOS, WAKKART, WAKKVAR, WAKKFARBE, WAKBAUMKZ, WAKVERWEN, WAKANZBA, WAKDIVISOR, WAKEAFAKTM, WAKEAFAKTR, WAKDISPOKZ, WAKSTBR, WAKLLEIST, WAKRLEIST, WAKRBEM, WAKNET, WAKBRUT, WAKROSTA, WAKSBSTUE, WAKEARUE, WAKSTICH, WAKSCHIEART, WAKSCHIENE, WAKLAENG, WAKEINL, WAKSPANNV, WAKSPANNB, WAKSPANNF, WAKVERSATZ, WAKVARKZ, WAKABFFDZ, WAKUSEDFDZ, WAKFILLER, WAKAENZL, WAKAENB, WAKAEND, WAKNEUB, WAKNEUD)"
                + " VALUES (:WAKMANDANT, '00000000', '   ', '   ', :WAKART, :WAKVAR, :WAKWCOL, :WAKPOS, '                    ', '  ', '          ', 'Z', 'S', '01', '01', 0, 0, 'B', 'D', '    ', '    ', '                 ', 0, 0, 'N', 'V', 0, 0, ' ', '     ', 0, 0, 0, 0, '00', 0, ' ', 0, 0, '                      ', 0, '        ', 0, '        ', 0)";
            or1.Parameters.Add("WAKMANDANT", OracleType.NVarChar).Value = dwData["WAKMANDANT"].ToString();
            or1.Parameters.Add("WAKART", OracleType.NVarChar).Value = dwData["WAKART"].ToString();
            or1.Parameters.Add("WAKVAR", OracleType.NVarChar).Value = dwData["WAKVAR"].ToString();
            or1.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value = dwData["WAKWCOL"].ToString();
            or1.Parameters.Add("WAKPOS", OracleType.NVarChar).Value = dwData["WAKPOS"].ToString();
            setResult = Connect2Proxy(or1);
        }
        public void DeleteWASTKE(string client, string art, string var, string color)
        {

            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE WASTKE"
           + " WHERE WAKMANDANT=:WAKMANDANT AND WAKART=:WAKART AND WAKVAR=:WAKVAR AND WAKWCOL=:WAKWCOL";
            or1.Parameters.Add("WAKMANDANT", OracleType.NVarChar).Value = client;
            or1.Parameters.Add("WAKART", OracleType.NVarChar).Value = art;
            or1.Parameters.Add("WAKVAR", OracleType.NVarChar).Value = var;
            or1.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value = color;
            Connect2Proxy(or1);
        }
        public DataSet QueryWASTKE(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WASTKE WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM WASTKE"
                   + " WHERE WAKMANDANT=:WAKMANDANT AND WAKART=:WAKART AND WAKVAR=:WAKVAR AND WAKWCOL=:WAKWCOL";
                    or1.Parameters.Add("WAKMANDANT", OracleType.NVarChar).Value = dwData["WAKMANDANT"].ToString();
                    or1.Parameters.Add("WAKART", OracleType.NVarChar).Value = dwData["WAKART"].ToString();
                    or1.Parameters.Add("WAKVAR", OracleType.NVarChar).Value = dwData["WAKVAR"].ToString();
                    or1.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value = dwData["WAKWCOL"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT DISTINCT WDAUFKRS,WDAUFLFD,WDAUFPOS, K.* FROM WDECK  WD "
                        + " JOIN WASTAMM W ON WDART=W.WAART AND WDVAR=W.WAVAR"
                        + " JOIN WASTKE K ON WAART=WAKART AND WAVAR=WAKVAR AND WAKWCOL=WDFARBE"
                        + " WHERE WDMANDANT=:WDMANDANT AND WDSA='K' AND WDTYP='B' AND WDWAKZ='F' AND WDAUFKRS=:WDAUFKRS  AND WDAUFLFD=:WDAUFLFD";
                    or1.Parameters.Add("WDMANDANT", OracleType.NVarChar).Value = dwData["WDMANDANT"].ToString();
                    or1.Parameters.Add("WDAUFKRS", OracleType.NVarChar).Value = dwData["WDAUFKRS"].ToString();
                    or1.Parameters.Add("WDAUFLFD", OracleType.NVarChar).Value = dwData["WDAUFLFD"].ToString();
                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "WASTKE";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateWASTKE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE WASTKE SET "
                + "WAKMANDANT=:WAKMANDANT,"
                + "WAKKUNDNR=:WAKKUNDNR,"
                + "WAKWERK=:WAKWERK,"
                + "WAKABT=:WAKABT,"
                + "WAKART=:WAKART,"
                + "WAKVAR=:WAKVAR,"
                + "WAKWCOL=:WAKWCOL,"
                + "WAKPOS=:WAKPOS,"
                + "WAKKART=:WAKKART,"
                + "WAKKVAR=:WAKKVAR,"
                + "WAKKFARBE=:WAKKFARBE,"
                + "WAKBAUMKZ=:WAKBAUMKZ,"
                + "WAKVERWEN=:WAKVERWEN,"
                + "WAKANZBA=:WAKANZBA,"
                + "WAKDIVISOR=:WAKDIVISOR,"
                + "WAKEAFAKTM=:WAKEAFAKTM,"
                + "WAKEAFAKTR=:WAKEAFAKTR,"
                + "WAKDISPOKZ=:WAKDISPOKZ,"
                + "WAKSTBR=:WAKSTBR,"
                + "WAKLLEIST=:WAKLLEIST,"
                + "WAKRLEIST=:WAKRLEIST,"
                + "WAKRBEM=:WAKRBEM,"
                + "WAKNET=:WAKNET,"
                + "WAKBRUT=:WAKBRUT,"
                + "WAKROSTA=:WAKROSTA,"
                + "WAKSBSTUE=:WAKSBSTUE,"
                + "WAKEARUE=:WAKEARUE,"
                + "WAKSTICH=:WAKSTICH,"
                + "WAKSCHIEART=:WAKSCHIEART,"
                + "WAKSCHIENE=:WAKSCHIENE,"
                + "WAKLAENG=:WAKLAENG,"
                + "WAKEINL=:WAKEINL,"
                + "WAKSPANNV=:WAKSPANNV,"
                + "WAKSPANNB=:WAKSPANNB,"
                + "WAKSPANNF=:WAKSPANNF,"
                + "WAKVERSATZ=:WAKVERSATZ,"
                + "WAKVARKZ=:WAKVARKZ,"
                + "WAKABFFDZ=:WAKABFFDZ,"
                + "WAKUSEDFDZ=:WAKUSEDFDZ,"
                + "WAKFILLER=:WAKFILLER,"
                + "WAKAENZL=:WAKAENZL,"
                + "WAKAENB=:WAKAENB,"
                + "WAKAEND=:WAKAEND,"
                + "WAKNEUB=:WAKNEUB,"
                + "WAKNEUD=:WAKNEUD "
                + " WHERE  "
                + "  WAKMANDANT=:WAKMANDANT AND WAKART=:WAKART  AND WAKVAR=:WAKVAR  AND WAKWCOL=:WAKWCOL";
            or1.Parameters.Add("WAKMANDANT", OracleType.NVarChar).Value = dwData["WAKMANDANT"].ToString();
            or1.Parameters.Add("WAKKUNDNR", OracleType.NVarChar).Value = dwData["WAKKUNDNR"].ToString();
            or1.Parameters.Add("WAKWERK", OracleType.NVarChar).Value = dwData["WAKWERK"].ToString();
            or1.Parameters.Add("WAKABT", OracleType.NVarChar).Value = dwData["WAKABT"].ToString();
            or1.Parameters.Add("WAKART", OracleType.NVarChar).Value = dwData["WAKART"].ToString();
            or1.Parameters.Add("WAKVAR", OracleType.NVarChar).Value = dwData["WAKVAR"].ToString();
            or1.Parameters.Add("WAKWCOL", OracleType.NVarChar).Value = dwData["WAKWCOL"].ToString();
            or1.Parameters.Add("WAKPOS", OracleType.NVarChar).Value = dwData["WAKPOS"].ToString();
            or1.Parameters.Add("WAKKART", OracleType.NVarChar).Value = dwData["WAKKART"].ToString();
            or1.Parameters.Add("WAKKVAR", OracleType.NVarChar).Value = dwData["WAKKVAR"].ToString();
            or1.Parameters.Add("WAKKFARBE", OracleType.NVarChar).Value = dwData["WAKKFARBE"].ToString();
            or1.Parameters.Add("WAKBAUMKZ", OracleType.NVarChar).Value = dwData["WAKBAUMKZ"].ToString();
            or1.Parameters.Add("WAKVERWEN", OracleType.NVarChar).Value = dwData["WAKVERWEN"].ToString();
            or1.Parameters.Add("WAKANZBA", OracleType.NVarChar).Value = dwData["WAKANZBA"].ToString();
            or1.Parameters.Add("WAKDIVISOR", OracleType.NVarChar).Value = dwData["WAKDIVISOR"].ToString();
            or1.Parameters.Add("WAKEAFAKTM", OracleType.NVarChar).Value = dwData["WAKEAFAKTM"].ToString();
            or1.Parameters.Add("WAKEAFAKTR", OracleType.NVarChar).Value = dwData["WAKEAFAKTR"].ToString();
            or1.Parameters.Add("WAKDISPOKZ", OracleType.NVarChar).Value = dwData["WAKDISPOKZ"].ToString();
            or1.Parameters.Add("WAKSTBR", OracleType.NVarChar).Value = dwData["WAKSTBR"].ToString();
            or1.Parameters.Add("WAKLLEIST", OracleType.NVarChar).Value = dwData["WAKLLEIST"].ToString();
            or1.Parameters.Add("WAKRLEIST", OracleType.NVarChar).Value = dwData["WAKRLEIST"].ToString();
            or1.Parameters.Add("WAKRBEM", OracleType.NVarChar).Value = dwData["WAKRBEM"].ToString();
            or1.Parameters.Add("WAKNET", OracleType.NVarChar).Value = dwData["WAKNET"].ToString();
            or1.Parameters.Add("WAKBRUT", OracleType.NVarChar).Value = dwData["WAKBRUT"].ToString();
            or1.Parameters.Add("WAKROSTA", OracleType.NVarChar).Value = dwData["WAKROSTA"].ToString();
            or1.Parameters.Add("WAKSBSTUE", OracleType.NVarChar).Value = dwData["WAKSBSTUE"].ToString();
            or1.Parameters.Add("WAKEARUE", OracleType.NVarChar).Value = dwData["WAKEARUE"].ToString();
            or1.Parameters.Add("WAKSTICH", OracleType.NVarChar).Value = dwData["WAKSTICH"].ToString();
            or1.Parameters.Add("WAKSCHIEART", OracleType.NVarChar).Value = dwData["WAKSCHIEART"].ToString();
            or1.Parameters.Add("WAKSCHIENE", OracleType.NVarChar).Value = dwData["WAKSCHIENE"].ToString();
            or1.Parameters.Add("WAKLAENG", OracleType.NVarChar).Value = dwData["WAKLAENG"].ToString();
            or1.Parameters.Add("WAKEINL", OracleType.NVarChar).Value = dwData["WAKEINL"].ToString();
            or1.Parameters.Add("WAKSPANNV", OracleType.NVarChar).Value = dwData["WAKSPANNV"].ToString();
            or1.Parameters.Add("WAKSPANNB", OracleType.NVarChar).Value = dwData["WAKSPANNB"].ToString();
            or1.Parameters.Add("WAKSPANNF", OracleType.NVarChar).Value = dwData["WAKSPANNF"].ToString();
            or1.Parameters.Add("WAKVERSATZ", OracleType.NVarChar).Value = dwData["WAKVERSATZ"].ToString();
            or1.Parameters.Add("WAKVARKZ", OracleType.NVarChar).Value = dwData["WAKVARKZ"].ToString();
            or1.Parameters.Add("WAKABFFDZ", OracleType.NVarChar).Value = dwData["WAKABFFDZ"].ToString();
            or1.Parameters.Add("WAKUSEDFDZ", OracleType.NVarChar).Value = dwData["WAKUSEDFDZ"].ToString();
            or1.Parameters.Add("WAKFILLER", OracleType.NVarChar).Value = dwData["WAKFILLER"].ToString();
            or1.Parameters.Add("WAKAENZL", OracleType.NVarChar).Value = dwData["WAKAENZL"].ToString();
            or1.Parameters.Add("WAKAENB", OracleType.NVarChar).Value = dwData["WAKAENB"].ToString();
            or1.Parameters.Add("WAKAEND", OracleType.NVarChar).Value = dwData["WAKAEND"].ToString();
            or1.Parameters.Add("WAKNEUB", OracleType.NVarChar).Value = dwData["WAKNEUB"].ToString();
            or1.Parameters.Add("WAKNEUD", OracleType.NVarChar).Value = dwData["WAKNEUD"].ToString();
            Connect2Proxy(or1);
        }
    }
}
